package com.qlslylq.ad.sdk.core.factory;

import com.qlslylq.ad.sdk.core.ad.BannerAd;
import com.qlslylq.ad.sdk.core.ad.BaseAd;
import com.qlslylq.ad.sdk.core.ad.FeedAd;
import com.qlslylq.ad.sdk.core.ad.FullScreenAd;
import com.qlslylq.ad.sdk.core.ad.InterstitialAd;
import com.qlslylq.ad.sdk.core.ad.RewardAd;
import com.qlslylq.ad.sdk.core.ad.SplashAd;
import com.qlslylq.ad.sdk.model.rsp.AdPlaceWebConfigureVO;

import java.util.ArrayList;
import java.util.List;

/**
 * created by qlslylq <br/>
 * on 2022/2/12 <br/>
 */
public class AdFactory {

    /**
     * 创建广告<br/>
     */
    public static <T extends BaseAd> T createAd(Object adThird, AdPlaceWebConfigureVO config) {
        T ad = null;
        if (adThird == null) {
            return null;
        }

        switch (config.getAdType()) {
            case SPLASH:
                ad = (T) new SplashAd(adThird, config);
                break;
            case INTERSTITIAL:
                ad = (T) new InterstitialAd(adThird, config);
                break;
            case REWARDED:
                ad = (T) new RewardAd(adThird, config);
                break;
            case FULLSCREEN:
                ad = (T) new FullScreenAd(adThird, config);
                break;
            case BANNER:
                ad = (T) new BannerAd(adThird, config);
                break;
            case FEED:
                ad = (T) new FeedAd(adThird, config);
                break;
        }
        return ad;
    }

    /**
     * 创建广告<br/>
     */
    public static <T extends BaseAd> List<T> createAds(List<?> adThirds, AdPlaceWebConfigureVO config) {
        List<T> ads = new ArrayList<>();
        if (adThirds == null) {
            return ads;
        }

        switch (config.getAdType()) {
            case SPLASH:
                adThirds.forEach(item -> {
                    if (item != null) {
                        ads.add((T) new SplashAd(item, config));
                    }
                });
                break;
            case INTERSTITIAL:
                adThirds.forEach(item -> {
                    if (item != null) {
                        ads.add((T) new InterstitialAd(item, config));
                    }
                });
                break;
            case REWARDED:
                adThirds.forEach(item -> {
                    if (item != null) {
                        ads.add((T) new RewardAd(item, config));
                    }
                });
                break;
            case FULLSCREEN:
                adThirds.forEach(item -> {
                    if (item != null) {
                        ads.add((T) new FullScreenAd(item, config));
                    }
                });
                break;
            case BANNER:
                adThirds.forEach(item -> {
                    if (item != null) {
                        ads.add((T) new BannerAd(item, config));
                    }
                });
                break;
            case FEED:
                adThirds.forEach(item -> {
                    if (item != null) {
                        ads.add((T) new FeedAd(item, config));
                    }
                });
                break;
        }
        return ads;
    }

}
